package jgl.vajra.kingkong.part.vehicle.activity;

import android.text.TextUtils;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.orhanobut.logger.Logger;

import java.util.HashMap;
import java.util.Map;

import jgl.vajra.kingkong.R;
import jgl.vajra.kingkong.bean.OrderDetailsCompleteBean;
import jgl.vajra.kingkong.databinding.ActivityOrderDetailsCompleteBinding;
import jgl.vajra.kingkong.manager.AccountManager;
import jgl.vajra.kingkong.part.vehicle.contract.OrderDetailsCompleteContract;
import jgl.vajra.kingkong.part.vehicle.viewModel.OrderDetailsCompleteViewModel;
import jgl.vajra.kingkong.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.kingkong.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.kingkong.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.kingkong.widget.utils.UIUtils;

@CreateViewModel(OrderDetailsCompleteViewModel.class)
public class OrderDetailsCompleteActivity extends BaseMVVMActivity<OrderDetailsCompleteViewModel, ActivityOrderDetailsCompleteBinding> implements OrderDetailsCompleteContract.View {

    private String orderId;
    private SingleTypeBindingAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_details_complete;
    }

    @Override
    public void initView() {
        super.initView();
        orderId = getIntent().getStringExtra("orderId");

        // 不可嵌套滑动
        mBinding.recyclerView.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.recyclerView.setFocusableInTouchMode(false);
        //设置布局管理器
        mBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new SingleTypeBindingAdapter(this, null, R.layout.item_order_details_complete);
        mBinding.recyclerView.setAdapter(adapter);


        requestNetData();
    }

    private void requestNetData() {
        Map<String, Object> map = new HashMap<>();
        map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
        map.put("orderId", orderId);

        mViewModel.getOrderDetailsCompleteData(map);
    }

    @Override
    public void returnOrderDetailsCompleteData(OrderDetailsCompleteBean data) {
        mBinding.toolbar.setTitleText(data.titleHing);
        data.newCatchNumber = "接单数:" + data.catchNumber + "单";

        data.statusText = "退款中";
        if (!TextUtils.isEmpty(data.refundStatusOneDate)) {
            data.refundStatus = 1;
        }
        if (!TextUtils.isEmpty(data.refundStatusTwoDate)) {
            data.refundStatus = 2;
        }
        if (!TextUtils.isEmpty(data.refundStatusThreeDate)) {
            data.refundStatus = 3;
            data.statusText = "退款成功";
        }
        Logger.d(data.refundStatus);

        adapter.refresh(data.address);
        mBinding.setData(data);
    }
}
